
#include "matching.h"
#include "../../engine.h"

#include "../../User.h"

#include "../../NLogic/Static.h"
#include "../../NLogic/Battle.h"

namespace ProjectZ { namespace NCommand { namespace NMatching {

void CS_DUNGEON_OUT_REQ::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
	/*
	 * 던젼 종료
	SC_DUNGEON_OUT_REQ	0x0816		4	unsigned int	GID : 게임유니크 KEY
				2	unsigned short	퇴장할 맵ID
				2	char	세팅될X좌표
				2	char	세팅될 Y좌표
				2	unsigned short	"방향 벡터(보고있는 방향
	0 : RIGHT, 90 : DOWN..)"

	방장 : 던젼 입장 요청
	CS_DUNGEON_ENTER_REQ	0x0817		2	unsigned short	퇴장할 맵ID
				2	char	세팅될X좌표
				2	char	세팅될 Y좌표
				2	unsigned short	"방향 벡터(보고있는 방향
	0 : RIGHT, 90 : DOWN..)"
	 *
	 */
	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{

		return;
	}

	if (false == pSpace->IsDungeon())
	{
		DEBUGLOG("CS_DUNGEON_OUT_REQ space is not single or party dungeion");
		return;
	}

	int gid = 0;
	int exit_map_id = 1;

	PREPARE_PACKET;

	//pPacket->ParseMsg("%d", &gid);
	* pPacket >> gid;

	pSpace->LeaveUser(pUser);

//		NLogic::Space * pWorld = pUser->GetOldWorldSpace();
//		if (NULL == pWorld)
//		{
//			pSpace = NLogic::Static::Instance().GETWORLDSPACETREE().begin()->second;
//		}
//
//	Player_Info & player_info = pUser->player_info;

	//NLogic::Battle::Data & clsBattleData = pUser->GetBattle()->GetData();



	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pAck << pUser->GetUserSeq();
	* pAck << static_cast<uint16_t>(exit_map_id);
	* pAck << static_cast<uint16_t>(ConstPosX);
	* pAck << static_cast<uint16_t>(ConstPosY);
	* pAck << static_cast<uint16_t>(ConstDegree);

	//pAck->MsgCat("%d%2d%2d%2d%2d", pUser->GetUserSeq(), exit_map_id, clsBattleData.x, clsBattleData.y, clsBattleData.degree);
	pAck->MakePacket(CMD_SC_DUNGEON_OUT_REQ);
	pUser->Send(pAck);

	//pWorld->EnterUser(pUser);
}

} /*NWorld*/ } /*NCommand*/ } /*ProjectZ*/

